package b_shuzu;

import cn.hutool.core.date.StopWatch;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName CpuHuanCunJubuXing
 * @Description
 * @Author Zhang Li Tao
 * @Date 2024/4/5
 * @Version 1.0
 **/
public class CpuHuanCunJubuXing {
    public static void main(String[] args) {
        int rows = 1000000;
        int columns = 14;
        int[][] a = new int[rows][columns];

        StopWatch watch = StopWatch.create("test_cpu");
        watch.start("ij");
        ij(a, rows, columns);
        watch.stop();

        watch.start("ji");
        ji(a, rows, columns);
        watch.stop();

        System.out.println(watch.prettyPrint(TimeUnit.NANOSECONDS));
    }

    public static void ij(int[][] a, int rows, int columns) {
        long sum = 0L;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                sum += a[i][j];
            }
        }
    }

    public static void ji(int[][] a, int rows, int columns) {
        long sum = 0L;
        for (int j = 0; j < columns; j++) {
            for (int i = 0; i < rows; i++) {
                sum += a[i][j];
            }
        }
    }
}
